import { request } from '@/utils/request'
import { LoginType, ServiceType } from '@/config'
import type {
  PermissionFeatureTreePageParam,
  PermissionFeatureTreeResponse,
  PermissionFeatureResponse,
  PermissionFeatureRequest,
} from '@/types/permissionFeature'
import type { PageData } from '@/types/response'

export const permissionFeatureService = {
  /**
   * 树形分页查询功能权限
   * @param params 分页查询参数
   */
  getPermissionFeatureTree: (params: PermissionFeatureTreePageParam) =>
    request.post<PageData<PermissionFeatureTreeResponse>>('/permissionfeature/tree/page', {
      body: params,
      serviceType: ServiceType.AUTH,
      customHeaders: { loginType: LoginType.ADMIN },
    }),

  /** 创建功能权限 */
  createPermissionFeature(data: PermissionFeatureRequest): Promise<PermissionFeatureResponse> {
    return request.post('/permissionfeature', {
      body: data,
      serviceType: ServiceType.AUTH,
      customHeaders: { loginType: LoginType.ADMIN },
    })
  },

  /** 修改功能权限 */
  modifyPermissionFeature(data: PermissionFeatureRequest): Promise<PermissionFeatureResponse> {
    return request.put('/permissionfeature', {
      body: data,
      serviceType: ServiceType.AUTH,
      customHeaders: { loginType: LoginType.ADMIN },
    })
  },

  /**
   * 修改功能权限状态
   * @param params 修改状态参数
   */
  modifyStatus(params: { permissionId: string; permissionStatus: number }) {
    return request.put(`/permissionfeature/status`, {
      serviceType: ServiceType.AUTH,
      customHeaders: { loginType: LoginType.ADMIN },
      body: params,
    })
  },

  /**
   * 删除功能权限
   * @param permissionId 功能权限ID
   */
  deletePermissionFeature(permissionId: string) {
    return request.delete<PermissionFeatureResponse>(`/permissionfeature/${permissionId}`, {
      serviceType: ServiceType.AUTH,
      customHeaders: { loginType: LoginType.ADMIN },
    })
  },
}
